package com.cc.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

public class LogAspect {
    public void beforeAdvice(JoinPoint joinPoint) {
        System.out.println("=====我是前置通知=====>" + joinPoint);
    }
    public void afterAdvice(JoinPoint joinPoint) {
        System.out.println("=====我是后置通知=====>" + joinPoint);
    }
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("1.鉴权");
        // 调用目标方法
        Object result = joinPoint.proceed();
        System.out.println("1.日志留痕==》" + result);
        return result;
    }
    public Object logReturn(JoinPoint joinPoint, Object result) {
        System.out.println("" + joinPoint.getSignature().getName() + "正常返回。。。@AfterReturning:运行结果：{" + result + "}");
        return result;
    }

    // 6.异常通知
    public void logException(JoinPoint joinPoint, Exception exception) {
        System.out.println("" + joinPoint.getSignature().getName() + "异常。。。异常信息：{" + exception + "}");
    }
}
